package com.example.springboot.controller;

import com.example.springboot.common.Result;
import com.example.springboot.domain.po.Activity;
import com.example.springboot.service.ActivityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Api(tags = "活动管理接口")
@CrossOrigin
@RestController
@RequestMapping("/activity")
public class ActivityController {
    @Resource
    ActivityService activityService;


    @ApiOperation("查询所有数据")
    @GetMapping("/alldata")
    public Result getData() {
        return Result.success(activityService.GetAll());
    }

    @ApiOperation("新增活动接口")
    @PostMapping
    public Result activityAdd(@RequestBody Activity activity) {
        return Result.success(activityService.add(activity));
    }


    @ApiOperation("根据ID删除")
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id) {
        activityService.delete(id);
        return Result.success();
    }


    @ApiOperation("分页查询")
    @PostMapping("/page")
    public Result page(@RequestBody Activity search,
                       @RequestParam(defaultValue = "1") Integer pageNum,
                       @RequestParam(defaultValue = "5") Integer pageSize) {
        return Result.success(activityService.findPage(search, pageNum, pageSize));
    }

    @ApiOperation("编辑活动信息接口")
    @PostMapping("/edit")
    public Result activityEdit(@RequestBody Activity activity) {
        return Result.success(activityService.activityEdit(activity));
    }

}